package com.derekandbritt.booST.server;

import java.util.Calendar;
import java.util.TimeZone;

public class CalendarUtil {

    private static final TimeZone EST_ZONE = TimeZone.getTimeZone("GMT-5");
    
    public static long getCurrentDay() {
        Calendar cal = Calendar.getInstance(EST_ZONE);
        cal.clear(Calendar.HOUR);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTimeInMillis();
    }
    
    public static long getLastInterval() {
        
        Calendar cal = Calendar.getInstance(EST_ZONE);
        if(cal.get(Calendar.HOUR_OF_DAY) > 12) {
            cal.clear(Calendar.HOUR);
            cal.set(Calendar.HOUR_OF_DAY, 12);
        } else {
            cal.clear(Calendar.HOUR);
            cal.set(Calendar.HOUR_OF_DAY, 0);
        }
        
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTimeInMillis();
    }
}
